package athabasca.ca.model;

import java.util.ArrayList;
import java.util.Date;

public class FeatureSelection
{
    private User trackedUser;
    private ArrayList<TrackedFeature> selectedFeatures;
    private Date start, end;
    
    public FeatureSelection ( User trackedUser, Date timestampStart )
    {
    	this.trackedUser = trackedUser;
        this.selectedFeatures = new ArrayList < TrackedFeature > ( );
        
        this.start = timestampStart;
    }
    
    public FeatureSelection (User trackedUser, TrackedFeature[] trackedFeatures, Date timestampStart )
    {
        this.trackedUser = trackedUser;
        this.selectedFeatures = new ArrayList < TrackedFeature > ( );
        
        for ( TrackedFeature tf : trackedFeatures ) selectedFeatures.add(tf);
        
        this.start = timestampStart;
        this.end = null;
    }
        
    public void setTrackedUser(User trackedUser)
    {
        this.trackedUser = trackedUser;
    }
    
    public User getTrackedUser()
    {
        return trackedUser;
    }
    
    public void setStartDate ( Date start )
    {
        this.start = start;
    }
    
    public Date getStartDate ( )
    {
        return this.start;
    }
    
    public void setEndDate ( Date end )
    {
        this.end = end;
    }
    
    public Date getEndDate ( )
    {
        return this.end;
    }
    
    public boolean addNewTrackedFeature(TrackedFeature newTrackedFeature)
    {
        return selectedFeatures.add(newTrackedFeature);
    }
    
    public boolean removeTrackedFeature(TrackedFeature removedTrackedFeature)
    {
        return selectedFeatures.remove(removedTrackedFeature);
    }
    
    public void addTrackedFeatures ( ArrayList<TrackedFeature> selectedFeatures)
    {
        this.selectedFeatures = selectedFeatures;
    }
    
    public TrackedFeature [ ] getTrackedFeatures ( )
    {
        return ( TrackedFeature [ ] ) selectedFeatures.toArray( new TrackedFeature [ selectedFeatures.size ( ) ] );
    }
    
    public TrackedFeature getTrackedFeatureByName ( String featureName )
    {
    	for ( TrackedFeature tF : selectedFeatures )
    	{
    		if ( tF.getName ( ).equals( featureName ) ) return tF;
    	}
    	
    	return null;
    }
    
    // TODO: return tracked features that started @timestamp
    // TODO: return tracked features that closed @timestamp
    // TODO: return tracked features within certain period (@timestamp's)
}